package com.xindacloud.sms.console.system.service.impl;

import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xindacloud.sms.console.result.Result;
import com.xindacloud.sms.console.result.ResultGenerator;
import com.xindacloud.sms.console.system.dto.SmsApiDTO;
import com.xindacloud.sms.console.system.dto.SmsUiContentDTO;
import com.xindacloud.sms.console.system.entity.SmsApi;
import com.xindacloud.sms.console.system.mapper.SmsApiMapper;
import com.xindacloud.sms.console.system.service.ISmsApiService;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author czc
 * @since 2019-11-28
 */
@Service
public class SmsApiServiceImpl extends ServiceImpl<SmsApiMapper, SmsApi> implements ISmsApiService {

	@Override
	public Result getSmsApiList(SmsApiDTO smsApiDTO) {
		IPage<SmsApi> page=new Page<>(smsApiDTO.getPageNum(),smsApiDTO.getPageSize());
		QueryWrapper<SmsApi> queryWrapper=new QueryWrapper<>();
		/*if(smsApiDTO.getName()!=null) {
		queryWrapper.eq("name", smsApiDTO.getName());
		}*/
		return ResultGenerator.genSuccessResult(this.page(page,queryWrapper));
	}

	@Override
	public Result saveOrUpdateSmsApi(SmsApiDTO smsApiDTO) {
		SmsApi smsApi=new SmsApi();
		try {
			BeanUtils.copyProperties(smsApiDTO,smsApi);
		} catch (Exception e) {
			e.printStackTrace();
		}
		if(this.saveOrUpdate(smsApi)){
		    return ResultGenerator.genSuccessResult("保存或修改成功！");
		}else {
			return ResultGenerator.genClientFailResult("保存或修改失败！");
		}
	}

	@Override
	public Result deleteSmsApi(SmsApiDTO smsApiDTO) {
		if(this.removeById(smsApiDTO.getId())){
			return ResultGenerator.genSuccessResult("删除成功！");
		}else {
			return ResultGenerator.genClientFailResult("删除失败！");
		}
	}

}
